﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using BusinessObjects.BO_GetObjects;
using BussinessObjects;
using BusinessObjects;
using LibraryO2S;
using System.IO;
using System.Xml;

public partial class controls_admin_Video : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
            loadMovie();
    }
    private void loadMovie()
    {
        try
        {
            string fname = Server.MapPath("../upload/xml/video.xml");
            if (File.Exists(fname))
            {
                XmlDocument doc = new XmlDocument();
                doc.Load(fname);
                XmlNode root = doc.DocumentElement;
                XmlNodeList list = root.ChildNodes;
                txtVideoName.Text = list.Item(0).InnerText;
                txtLink.Text = list.Item(1).InnerText;
            }
        }
        catch (Exception ex)
        {
            divMessage.InnerHtml = O2S_Message.Error("Lỗi", "Phát hiện lỗi :<br />" + ex.Message);
        }
    }
    protected void btnEdit_Click(object sender, EventArgs e)
    {
        try
        {
            string fname = Server.MapPath("../upload/xml/video.xml");
            XmlTextWriter xw = new XmlTextWriter(fname, null);
            xw.Formatting = Formatting.Indented;
            xw.Indentation = 6;
            xw.WriteStartDocument();
            xw.WriteStartElement("Video");
            xw.WriteStartElement("Name");
            xw.WriteString(txtVideoName.Text.Trim());
            xw.WriteEndElement();
            xw.WriteStartElement("Link");
            xw.WriteString(txtLink.Text.Trim());
            xw.WriteEndElement();
            xw.WriteEndElement();
            xw.WriteEndDocument();
            xw.Flush();
            xw.Close();
            divMessage.InnerHtml = O2S_Message.Success("Thông Báo", "Cập nhật thành công.");
        }
        catch (Exception ex)
        {
            divMessage.InnerHtml = O2S_Message.Error("Lỗi", "Có lỗi xảy ra: " + ex.Message);
        }
    }
}
